/**
 * 劳动合同预览
 */
import React, { useCallback, useImperativeHandle, useState } from 'react';
import { Modal } from 'antd';
import { ResumeIframe } from '@/pages/Recruitment/components';
import styles from './index.less';

const EntryLaborContractPreview = React.forwardRef((props, ref) => {
    const [visible, setVisible] = useState(false);

    const [url, setUrl] = React.useState();

    useImperativeHandle(ref, () => ({
        open: urls => {
            setVisible(true);
            setUrl(urls);
        }
    }));

    const handleCancel = useCallback(() => {
        setVisible(false);
    }, []);

    return (
        <Modal width={952} title="预览" visible={visible} onCancel={handleCancel} footer={null}>
            <div className={styles.previewWrap}>
                <div className={styles.previewContainer}>
                    {url && (
                        <ResumeIframe
                            url={`https://view.officeapps.live.com/op/view.aspx?src=${encodeURIComponent(url)}`}
                            isNative={false}
                        />
                    )}
                </div>
            </div>
        </Modal>
    );
});

EntryLaborContractPreview.displayName = 'EntryLaborContractPreview';

export default React.memo(EntryLaborContractPreview);
